function productsViewModel(selectedCategoryId, selectedCategoryName) {
	var self = this;
	
	self.products = ko.observableArray();
	self.categories = ko.observableArray();
	self.selectedCategoryId = ko.observable(selectedCategoryId);
	self.selectedCategoryName = ko.observable(selectedCategoryName);
	self.categoriesVisible = ko.observable(false);
	self.orderBy = ko.observable('');
	
	self.orderByMostView = function() {
		self.orderBy("MostView");
		changeHashValue("order", "views");
		self.pager(new Pager({ webService: "product/getProductsByCategory", params : { "pageNumber" : 1, "pageSize" : 12, 'categoryId' : self.selectedCategoryId(), 'orderBy' : self.orderBy(), 'topPx': 0, 'changeUrl': true }, onSuccess: self.getProductsSuccess }));
	};
	
	self.orderByAlphabet = function(currentPage, currentCategory) {
		self.orderBy("");
		changeHashValue("order", "alphabet");
		self.pager(new Pager({ webService: "product/getProductsByCategory", params : { "pageNumber" : 1, "pageSize" : 12, 'categoryId' : self.selectedCategoryId(), 'orderBy' : self.orderBy(), 'topPx': 0, 'changeUrl': true }, onSuccess: self.getProductsSuccess }));
	};
	
	self.toggleCategoriesVisibility = function() {
		self.categoriesVisible(!self.categoriesVisible());
	};
	
	self.selectCategory = function(category) {
		self.selectedCategoryName(category.name);
		self.selectedCategoryId(category.id);
		changeHashValue("category", category.id);
		self.pager(new Pager({ webService: "product/getProductsByCategory", params : { "pageNumber" : 1, "pageSize" : 12, 'categoryId' : category.id, 'orderBy' : self.orderBy(), 'topPx': 0, 'changeUrl': true }, onSuccess: self.getProductsSuccess }));
	};
	
	self.getProductsSuccess = function(products) {
		self.products($.map(products.elements, function (product) { return new Product(product); }));
	};
	
	self.getCategoriesSuccess = function(categories) {
		var allCategories = [{ "id" : 0, "name": "Todos" }];
		self.categories(allCategories.concat(categories));
	};
	
	self.showProducts = function(products) {
		$(products).show();
	};
	
	var currentPage = parseInt(getHashValue("page") || 1);
	var currentCategory = parseInt(getHashValue("category") || self.selectedCategoryId());
	if(getHashValue("order") == 'views') {
		self.orderBy("MostView");
	}
	
	self.pager = ko.observable(new Pager({ webService: "product/getProductsByCategory", params : { "pageNumber" : currentPage, "pageSize" : 12, 'categoryId' : currentCategory, 'orderBy' : self.orderBy(), 'topPx': 0, 'changeUrl': true }, onSuccess: self.getProductsSuccess }));
	
	getService("product/getCategories", { }, self.getCategoriesSuccess);
};